<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

if (!function_exists('iaMemberFieldSearch')) {

    function iaMemberFieldSearch($searchData = array())
    {
        $CI = & get_instance();
        $loading = $CI->lang->line('Loading');
        $_field_search = array(
            'textsearch' => array(
                'name' => 'textsearch',
                'id' => 'frm-textsearch',
                'class' => 'span3',
                'placeholder' => $CI->lang->line('Pls_enter_keyword'),
                'value' => set_value('textsearch', isset($searchData['textsearch']) ? $searchData['textsearch'] : '')
            ),
            'submit' => array('name' => 'btn-Search', 'class' => 'btn btn-primary', 'data-loading-text' => $loading,
                'id' => 'form-btnSearch', 'value' => $CI->lang->line('Search')),
            'reset' => array('name' => 'btn-Reset', 'class' => 'btn btn-primary', 'data-loading-text' => $loading,
                'id' => 'form-btnReset', 'value' => $CI->lang->line('Reset')),
        );

        return $_field_search;
    }

}

if (!function_exists('iaMemberFieldFilter')) {

    function iaMemberFieldFilter($filterData = array(), $filterSelected = 0)
    {
        $CI = & get_instance();
        $loading = $CI->lang->line('Loading');
        $_field_filter_attribute = array(
            'dropdown_filter' => array(
                'name' => 'type_id',
                'data' => $filterData,
                'selected' => $filterSelected,
                'extra' => "id='frm-ia-attribute-filter' class='span3'"
            ),
            'submit' => array(
                'name' => 'btn-Filter',
                'class' => 'btn btn-primary',
                'data-loading-text' => $loading,
                'id' => 'form-btnSearch',
                'value' => $CI->lang->line('Filter')),
            'reset' => array('name' => 'btn-Reset', 'class' => 'btn btn-primary', 'data-loading-text' => $loading,
                'id' => 'form-btnReset', 'value' => $CI->lang->line('Reset')),
        );

        return $_field_filter_attribute;
    }

}


//define field to generate form
if (!function_exists('iaMemberFieldForm')) {

    function iaMemberFieldForm($attribute = array(), $types = array())
    {
        $CI = & get_instance();
        if (count($attribute) && !empty($attribute)) {
            $name = $attribute->name;
            $active = $attribute->active;
            $selectedTypeId = $attribute->type_id;
        }

        $_field_form = array(
            'name' => array(
                'name' => 'name',
                'id' => 'frm-name',
                'class' => 'span3',
                'placeholder' => $CI->lang->line('Pls_enter_attribute'),
                'value' => set_value('name', isset($name) ? $name : '')),
            'type_id' => array(
                'name' => 'type_id',
                'options' => $types,
                'selected' => isset($selectedTypeId) ? array($selectedTypeId) : array(),
            ),
            'active' => array(
                'name' => 'active',
                'class' => 'class="checkActive"',
                'value' => 1,
                'checked' => (isset($active) && $active > 0) ? TRUE : FALSE
            ),
            'submit' => array('class' => 'btn btn-primary', 'data-loading-text' => $CI->lang->line('Loading'),
                'id' => 'form-submit', 'value' => $CI->lang->line('Save')),
        );

        return $_field_form;
    }

}

//define field to validate form
if (!function_exists('iaMemberFieldValidate')) {

    function iaMemberFieldValidate()
    {
        $CI = & get_instance();
        $_field_validate = array(
            array(
                'field' => 'order',
                'label' => $CI->lang->line('Order'),
                'rules' => 'trim|is_natural|xss_clean'
            ),
            array(
                'field' => 'name',
                'label' => $CI->lang->line('Question_Text'),
                'rules' => 'trim|required|xss_clean'
            ),
        );
        return $_field_validate;
    }

}